package yyds;



public class MyQueue {
    private int maxSize;
    private int head;
    private int tail;
    private int [] arr;

    //初始化
    public MyQueue(int maxSize) {
        this.maxSize = maxSize;
        arr = new int[maxSize];
        head =-1;
        tail = -1;
    }

//    判断队列是否已满
    public boolean isFull(){
        return tail==maxSize-1;
    }
//    判断队列是否为空
    public boolean isEmpty(){
        return tail==head;
    }

//    存数据
    public void addToQueue(int i){
        if (isFull()){
            System.out.println("队列已满，添加不了");
            return;
        }

        arr[++tail] = i;
    }
//    取数据
    public int getFromQueue(){
        if (isEmpty()){
//            throw new RuntimeException("队列为空，不能取数据");
            System.out.println("队列为空，不能取数据");
            return -1;
        }
        return arr[++head];
    }
//    显示队列的所有数据
    public void showQueue(){
        if (isEmpty()){
            System.out.println("队列为空");
            return;
        }
        for (int i = 0; i <arr.length ; i++) {
            System.out.println(arr[i]);
        }
    }
//    显示队列头
    public void oneQueue(){
        if (isEmpty()){
            System.out.println("队列为空");
            return;
        }
        System.out.println(arr[head+1]);
    }

}
